#pragma once
#include "DTriMeshData.h"
#include "DVertexBuffer.h"
#include "DIndexBuffer.h"

namespace Skill
{
	namespace Ode
	{
		namespace Geometries
		{			
			void DTriMeshData::CollectManagedMemory()
			{				
				_Indices = nullptr;				
				_Normals = nullptr;
				_Vertices = nullptr;
			}

			DTriMeshData::DTriMeshData(DVertexBuffer^ vertices,DIndexBuffer^ indices)
			{
				_SetPointer(dGeomTriMeshDataCreate(),true);
				_Vertices = vertices;
				_Indices = indices;

				dGeomTriMeshDataBuildSingle(_This,
					vertices->_This, vertices->VertexStride, vertices->VertexCount, 
					indices->_This, indices->IndexCount, indices->TriangleStride);								
			}
			DTriMeshData::DTriMeshData(DVertexBuffer^ vertices,DIndexBuffer^ indices , DVertexBuffer^ normals)
			{
				_SetPointer(dGeomTriMeshDataCreate(),true);
				_Vertices = vertices;
				_Indices = indices;
				_Normals = normals;				
				dGeomTriMeshDataBuildSingle1(_This,
					vertices->UnmanagedPointer.ToPointer(), vertices->VertexStride, vertices->VertexCount, 
					indices->_This, indices->IndexCount, indices->TriangleStride,normals->UnmanagedPointer.ToPointer());				
			}

			DVertexBuffer^ DTriMeshData::Vertices::get()
			{
				return _Vertices;
			}
			DVertexBuffer^ DTriMeshData::Normals::get()
			{
				return _Normals;
			}
			DIndexBuffer^ DTriMeshData::Indices::get()
			{
				return _Indices;
			}

			void DTriMeshData::Preprocess()
			{
				dGeomTriMeshDataPreprocess(_This);
			}
			void DTriMeshData::Update()
			{
				dGeomTriMeshDataUpdate(_This);
			}
		}
	}
}